﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MensUnoShop.Models
{
    public class SalesKitFactory
    {
        public static List<SalesKit> GetByLoginGiftSalesKitList()
        {
            return new List<SalesKit>();
        }

        public static List<SalesKit> GetByOrderGiftSalesKitList()
        {
            return new List<SalesKit>();
        }

        #region 買千折百相關
        public static List<USalesKit> GetManagerHanselList()
        {
            DBSaleskit dbs = new DBSaleskit(); 
            return dbs.GetManagerSalesKitList(Config.SalesKitKind.HanselDiscount);
        }

        public static USalesKit GetManagerHansel(string id)
        {
            DBSaleskit dbs = new DBSaleskit();
            return dbs.GetManagerSalesKit(new Guid(id), Config.SalesKitKind.HanselDiscount);
        }

        public static string AddManagerHansel(string stitle, string startdate, string enddate, ref string id)
        {
            DBSaleskit dbs = new DBSaleskit();
            string msg = string.Empty;
            DateTime st, et;
            DateTime.TryParse(startdate, out st);
            DateTime.TryParse(enddate, out et);
            Guid ssguid = Guid.Empty;
            msg = dbs.AddManagerSalesKit(stitle, string.Empty, string.Empty, st, et, Config.SalesKitRulesType.ByOrder, Config.SalesKitType.PriceDiscount, Config.SalesKitKind.HanselDiscount, ref ssguid);
            if (ssguid != Guid.Empty)
                id = ssguid.ToString();
            else
                id = "0";
            return msg;
        }

        public static string SetManagerHansel(string id, string stitle, string startdate, string enddate)
        {
            DateTime st, et;
            DateTime.TryParse(startdate, out st);
            DateTime.TryParse(enddate, out et);

            DBSaleskit dbs = new DBSaleskit();
            return dbs.SetManagerSalesKit(new Guid(id), string.Empty, stitle,string.Empty, st, et);
        }

        public static string DelManagerHansel(string id)
        {
            DBSaleskit dbs = new DBSaleskit();
            return dbs.DelManagerSalesKit(new Guid(id));
        }

        public static string UptManagerHanselStatus(string id)
        {
            DBSaleskit dbs = new DBSaleskit();
            return dbs.UptManagerSalesKitStatus(new Guid(id));
        }

        public static void GetManagerHanselList(string id, out List<USalesKitHandsel> handsellist)
        {
            DBSaleskit dbs = new DBSaleskit();
            dbs.GetManagerHanselList(new Guid(id), out handsellist);
        }

        public static void AddManagerHanselDetail(string id, string limit, string giftpoint, ref string msg)
        {
            DBSaleskit dbs = new DBSaleskit();
            Guid ssguid;
            int shlimit,shpoint;
            if(Guid.TryParse(id, out ssguid))
            {
                if (int.TryParse(limit, out shlimit) && int.TryParse(giftpoint, out shpoint))
                {
                    msg = dbs.AddManagerHanselDetail(ssguid, shlimit, shpoint);
                }
                else
                    msg = "活動參數錯誤!!";
            }
            else
                msg = "活動ID錯誤!!";
        }

        public static void DelManagerHanselDetail(string shid, ref string msg)
        {
            DBSaleskit dbs = new DBSaleskit();
            int intshid;
            if (int.TryParse(shid, out intshid))
            {
                msg = dbs.DelManagerHanselDetail(intshid);
            }
            else
                msg = "活動條件ID錯誤!!";
        }

        public static Dictionary<int, int> GetHanselJudgement()
        {
            DBSaleskit dbs = new DBSaleskit();
            Dictionary<int, int> judge = new Dictionary<int, int>();
            dbs.GetHanselJudgement(ref judge);
            return judge;
        }
        #endregion       
    
        
        #region 合購相關
        public static List<USalesKit> GetManagerComboList()
        {
            DBSaleskit dbs = new DBSaleskit();
            return dbs.GetManagerSalesKitList(Config.SalesKitKind.ComboDiscount);
        }
        
        public static string UptManagerComboStatus(string id)
        {
            DBSaleskit dbs = new DBSaleskit();
            return dbs.UptManagerSalesKitStatus(new Guid(id));
        }

        public static string DelManagerCombo(string id)
        {
            DBSaleskit dbs = new DBSaleskit();
            return dbs.DelManagerSalesKit(new Guid(id));
        }

        public static string AddManagerCombo(string stitle,string tagid,int pices, int comboprice, string startdate, string enddate, ref string id)
        {
            DBSaleskit dbs = new DBSaleskit();
            string msg = string.Empty;
            DateTime st, et;
            DateTime.TryParse(startdate, out st);
            DateTime.TryParse(enddate, out et);
            Guid ssguid = Guid.Empty;
            string note = string.Format("{0}|{1}", pices, comboprice);
            msg = dbs.AddManagerSalesKit(stitle, tagid.ToString(),note, st, et, Config.SalesKitRulesType.ByMarket, Config.SalesKitType.PriceDiscount, Config.SalesKitKind.ComboDiscount, ref ssguid);
            if (ssguid != Guid.Empty)
                id = ssguid.ToString();
            else
                id = "0";
            return msg;
        }

        public static string SetManagerCombo(string id, string stitle, string tagid, int pices, int comboprice, string startdate, string enddate)
        {
            DateTime st, et;
            DateTime.TryParse(startdate, out st);
            DateTime.TryParse(enddate, out et);
            string note = string.Format("{0}|{1}", pices, comboprice);
            DBSaleskit dbs = new DBSaleskit();
            return dbs.SetManagerSalesKit(new Guid(id), tagid.ToString(),stitle,note, st, et);
        }

        public static USalesKit GetCombo(long tagid)
        {
            DBSaleskit dbs = new DBSaleskit();
            return dbs.GetCombo(tagid);
        }

        public static USalesKit GetManagerCombo(string id)
        {
            DBSaleskit dbs = new DBSaleskit();
            return dbs.GetManagerSalesKit(new Guid(id), Config.SalesKitKind.ComboDiscount);
        }
        
        #endregion



       
    }
}